package com.tulele.vtool.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import com.tulele.vtool.mapper.BBusinessShareMapper;
import com.tulele.vtool.model.BBusinessShare;
import com.tulele.vtool.service.BBusinessShareService;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 商学院课程分享表(BBusinessShare)表服务实现类
 *
 * @author makejava
 * @since 2020-10-23 11:21:00
 */
@Service("bBusinessShareService")
public class BBusinessShareServiceImpl implements BBusinessShareService {
    @Resource
    private BBusinessShareMapper bBusinessShareMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public BBusinessShare queryById(Integer id) {
        return this.bBusinessShareMapper.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<BBusinessShare> queryAllByLimit(int offset, int limit) {
        return this.bBusinessShareMapper.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param bBusinessShare 实例对象
     * @return 实例对象
     */
    @Override
    public BBusinessShare insert(BBusinessShare bBusinessShare) {
        BBusinessShare bBusinessShareVo = new BBusinessShare();

        bBusinessShareVo.setUserId(bBusinessShare.getUserId());
        bBusinessShareVo.setCourseId(bBusinessShare.getCourseId());
        bBusinessShareVo.setTypes(1); //分享类型 1-商学院课程
        bBusinessShareVo.setDeleteState(1); //删除状态 0-删除 1-正常
        bBusinessShareVo.setCreateTime(new Date());
        bBusinessShareVo.setUpdateTime(new Date());

        this.bBusinessShareMapper.insert(bBusinessShareVo);
        return bBusinessShareVo;
    }

    /**
     * 修改数据
     *
     * @param bBusinessShare 实例对象
     * @return 实例对象
     */
    @Override
    public BBusinessShare update(BBusinessShare bBusinessShare) {
        this.bBusinessShareMapper.update(bBusinessShare);
        return this.queryById(bBusinessShare.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.bBusinessShareMapper.deleteById(id) > 0;
    }

    /**
     * 查询多条数据
     *
     * @param pageNum 查询起始位置
     * @param pageSize  查询条数
     * @param bBusinessShare 实例对象
     * @return 对象列表
     */
    @Override
    public PageInfo selectAllByLimit(Integer pageNum, Integer pageSize, BBusinessShare bBusinessShare) {

        PageHelper.startPage(pageNum, pageSize);

        bBusinessShare.setDeleteState(1); //字典状态 0-删除 1-正常
        List<BBusinessShare> bBusinessShareList = this.bBusinessShareMapper.queryAll(bBusinessShare);

        return new PageInfo<BBusinessShare>(bBusinessShareList);

    }
}